package mylab.io.core.util;

import java.util.Optional;

import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.timeout.IdleStateHandler;
import mylab.io.base.property.IdleAttrs;

public interface HandlerUtil {

    String HANDLER_NAME_LOG = "logHandler";
    String HANDLER_NAME_IDLE_STATE = "idleStateHandler";

    public static LoggingHandler newLoggingHandler(LogLevel logLevel) {
        return new LoggingHandler(Optional.of(logLevel).orElse(LogLevel.INFO));
    }

    public static IdleStateHandler newIdleStateHandler(IdleAttrs idleAttrs) {
        if (idleAttrs == null) {
            idleAttrs = new IdleAttrs();
        }

        return new IdleStateHandler(idleAttrs.getReaderIdleTimeSeconds(), idleAttrs.getWriterIdleTimeSeconds(), idleAttrs.getAllIdleTimeSeconds());
    }
}
